// pages/personally/personally.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMG: '../../pictures/basketball.jpg',
    avatarUrl: defaultAvatarUrl,
    username: "昵称",
    concern: 0,
    fan: 0,
    prise: 0,
    weight: 0,
    height: 0,
    goods: 0,
    star: 0,
    like_count: 0,
    id: '',
    ip: ''

  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail 
    this.setData({
      avatarUrl,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // var username
    var app = getApp()
    var ip = app.globalData.ServerAddress
    console.log(app.globalData.user_id)
    this.setData({
      id: app.globalData.user_id,
      ip: ip
    })
    let that = this
      wx.request({
        url: "http://" + ip + "/user/user_information",
        method: 'GET',
        dataType: "json",
        header: {
          'Content-type': 'application/json',
           "authorization": app.globalData.token
        },
        data: {
          id: app.globalData.user_id
        },
        success: function (res) {
          console.log(res)
          that.setData({
            username: res.data.id_name,
            concern: res.data.concern_count,
            fan: res.data.fans_count,
            prise: res.data.be_like_count,
            weight: res.data.weight + 'kg',
            height: res.data.height + 'cm',
            goods: res.data.goods,
            star: res.data.star_count,
            like_count: res.data.like_count
          })
        }
      }),
      wx.request({
        url: "http://" + ip + "/user/user_icon",
        method: 'GET',
        dataType: "json",
        header: {
          'Content-type': 'application/json',
          
        "authorization": app.globalData.token
        },
        data: {
          id: app.globalData.user_id
        },
        success: function (res) {
          // console.log(res)
          console.log(res)
          that.setData({
            IMG: "http://" + ip + "/user/user_icon?id="+ app.globalData.user_id
          })
        }
      })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading()
    //loading 提示框
    wx.showLoading({
      title: 'Loading...',
    })
    console.log("下拉刷新啦");
    setTimeout(function () {
      wx.hideLoading();
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000)
  },


  onPullDownRefresh() {
    var app = getApp()
    var ip = app.globalData.ServerAddress
    let that = this
    this.setData({
      IMG:  "http://" + ip + "/user/user_icon?id="+ app.globalData.user_id
    })
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.onRefresh()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
  
})